//商品更多评价页
//author：王梦阳

let itemComment = {
	getItemComment: function() {
		let itemId = localStorage.itemId;
		let htmlContentCT = ""; //装载评论标题
		let htmlContentCC = ""; //装载评论内容
		$.ajax({
			type: "GET",
			url: "http://39.98.158.247:8040/comment/get?type=i&id=" + itemId,
			success: function(data) {
				if (data.data.length == 0) {
					htmlContentCC +=
						`<span id="no-comment">该商品目前还没有评论</span>`;
					$(".comment-list").html(htmlContentCC);
				} else {
					htmlContentCT +=
					`<div class="all">全部(${data.data.length})</div>`;
					$(".comment-title").html(htmlContentCT);
					for (var i = 0; i < data.data.length; i++) {
						htmlContentCC +=
							`<div class="comment">
							    <img id="touxiang" src="${data.data[i].user_picture}"/>
								<span id="nickname">${data.data[i].user_name}</span>
								<div class="comment-content">${data.data[i].comment_content}</div>
							 </div>`;
					}
					$(".comment-list").html(htmlContentCC);
				}
			},
			error: function() {
				console.log("request error");
			}
		})
	}
}

window.onload = function() {
	itemComment.getItemComment();
}
